﻿using DotNetMVC.Common;
using DotNetMVC.IService;
using DotNetMVC.Website.Areas.WebAdmin.Models;
using System;
using System.Text;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DotNetMVC.DTO;
using DotNetMVC.Website.Areas.WebAdmin.Models.StaticPage;

namespace DotNetMVC.Website.Areas.WebAdmin.Common
{
    public class StaticPageHelper
    {
        public static ISiteNavService siteNavService = DependencyResolver.Current.GetService<ISiteNavService>();
        public static ISiteContentService siteContentService = DependencyResolver.Current.GetService<ISiteContentService>();

        #region 公用数据

        #region 递归遍历菜单
        private static string GetSiteNavs()
        {
            StringBuilder sb = new StringBuilder();
            SiteNavDTO[] allSiteNav = siteNavService.GetShowSiteNavs(2);

            SiteNavDTO[] siteNavs = allSiteNav.Where(e => e.ParentId == 0 && e.NavLevel == 1).ToArray();
            sb.Append("<ul class='menu clearfix'>");

            foreach (var nav in siteNavs)
            {
                sb.Append("<li>");
                sb.Append("<a href='" + nav.NavUrl + "'>" + nav.NavName + "</a>");
                SiteNavDTO[] childSiteNavs = allSiteNav.Where(e => e.ParentId == nav.Id && e.NavLevel == nav.NavLevel + 1).ToArray();
                if (childSiteNavs.Count() > 0)
                {
                    GetSiteNavs(sb, allSiteNav, childSiteNavs);
                }
                sb.Append("</li>");
            }
            sb.Append("</ul>");
            return sb.ToString();
        }

        /// <summary>
        /// 获取子菜单
        /// </summary>
        /// <param name="sb"></param>
        /// <param name="allSiteNav">所有菜单</param>
        /// <param name="siteNavs">当前菜单组</param>
        /// <param name="parentId"></param>
        private static void GetSiteNavs(StringBuilder sb, SiteNavDTO[] allSiteNav, SiteNavDTO[] siteNavs)
        {
            sb.Append("<ul class='menuChild'>");
            foreach (var nav in siteNavs)
            {
                sb.Append("<li>");
                sb.Append("<a href='" + nav.NavUrl + "'>" + nav.NavName + "</a>");

                SiteNavDTO[] childSiteNavs = allSiteNav.Where(e => e.ParentId == nav.Id && e.NavLevel == nav.NavLevel + 1).ToArray();
                if (childSiteNavs.Count() > 0)
                {
                    GetSiteNavs(sb, allSiteNav, childSiteNavs);
                }

                sb.Append("</li>");
            }
            sb.Append("</ul>");
        }
        #endregion

        /// <summary>
        /// 头部数据
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private static HeaderViewModel GetHeaderViewModel(ControllerContext context)
        {
            string cacheKey = "StaticPageHelper_Header";
            //先尝试去缓存中找
            HeaderViewModel model = (HeaderViewModel)context.HttpContext.Cache[cacheKey];
            if (model!=null)
            {
                //缓存的中的数据
                return model;
            }

            //头部链接菜单Id
            long navId;
            if (!long.TryParse(AdminHelper.GetSiteConfig(context).Headerlinks, out navId))
            {
                throw new ApplicationException("获取不到头部链接菜单Id");
            }

            model = new HeaderViewModel();
            model.HeaderLinks = siteContentService.GetDTOByNavId(navId, 10);
            model.SiteNavHTML = GetSiteNavs();

            //存入缓存
            context.HttpContext.Cache.Insert(cacheKey, model, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero);
            return model;
        }

        /// <summary>
        /// 清除头部缓存
        /// </summary>
        /// <param name="context"></param>
        public static void ClearHeaderCache(ControllerContext context)
        {
            string cacheKey = "StaticPageHelper_Header";
            //存入缓存
            context.HttpContext.Cache.Insert(cacheKey, null, null, DateTime.Now.AddMinutes(-1), TimeSpan.Zero);
        }

        /// <summary>
        /// 底部数据
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private static FooterViewModel GetFooterViewModel(ControllerContext context)
        {
            string cacheKey = "StaticPageHelper_Footer";
            //先尝试去缓存中找
            FooterViewModel model = (FooterViewModel)context.HttpContext.Cache[cacheKey];
            if (model != null)
            {
                //缓存的中的数据
                return model;
            }

            //头部链接菜单Id
            long navId;
            if (!long.TryParse(AdminHelper.GetSiteConfig(context).Footerlinks, out navId))
            {
                throw new ApplicationException("获取不到底部链接菜单Id");
            }
             model = new FooterViewModel();
            model.FooterlinksNavName = siteNavService.GetDTOById(navId).NavName;
            model.Footerlinks = siteContentService.GetDTOByNavId(navId, 10);

            //存入缓存
            context.HttpContext.Cache.Insert(cacheKey, model, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero);
            return model;
        }

        /// <summary>
        /// 清除头部缓存
        /// </summary>
        /// <param name="context"></param>
        public static void ClearFooterCache(ControllerContext context)
        {
            string cacheKey = "StaticPageHelper_Footer";
            //存入缓存
            context.HttpContext.Cache.Insert(cacheKey, null, null, DateTime.Now.AddMinutes(-1), TimeSpan.Zero);
        }
        #endregion

        /// <summary>
        /// 生成首页静态页
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static bool Home(ControllerContext context)
        {
            string template = "~/Areas/WebAdmin/Views/Template/Default.cshtml";
            string templateUrl = context.HttpContext.Server.MapPath(template);
            if (!File.Exists(templateUrl))
            {
                throw new Exception("获取不到首页生成静态页模板");
            }

            #region 获取数据
            //图片轮播
            long bannerNavId;
            if (!long.TryParse(AdminHelper.GetSiteConfig(context).Homebanner, out bannerNavId))
            {
                throw new ApplicationException("获取不到首页Banner菜单Id");
            }
            //最新通知
            long noticeNavId;
            if (!long.TryParse(AdminHelper.GetSiteConfig(context).HomeNotice, out noticeNavId))
            {
                throw new ApplicationException("获取不到首页最新通知菜单Id");
            }
            SiteNavDTO noitceNav = siteNavService.GetDTOById(noticeNavId);
            //书院要闻
            long newsNavId;
            if (!long.TryParse(AdminHelper.GetSiteConfig(context).HomeNews, out newsNavId))
            {
                throw new ApplicationException("获取不到首页书院要闻菜单Id");
            }
            SiteNavDTO newsNav = siteNavService.GetDTOById(newsNavId);
            //书院简介
            long aboutNavId;
            if (!long.TryParse(AdminHelper.GetSiteConfig(context).HomeAbout, out aboutNavId))
            {
                throw new ApplicationException("获取不到首页书院简介菜单Id");
            }
            //学在明德
            long studyNavId;
            if (!long.TryParse(AdminHelper.GetSiteConfig(context).HomeStudy, out studyNavId))
            {
                throw new ApplicationException("获取不到首页学在明德菜单Id");
            }
            SiteNavDTO studyNav = siteNavService.GetDTOById(studyNavId);
            #endregion

            HomeViewModel model = new HomeViewModel();

            #region 公共数据
            model.HeaderViewModel = GetHeaderViewModel(context);
            model.FooterViewModel = GetFooterViewModel(context);
            model.SiteConfig = AdminHelper.GetSiteConfig(context);
            #endregion

            model.Banner = siteContentService.GetDTOByNavId(bannerNavId, 5);
            model.NoitceNav = noitceNav;
            model.Noitce = siteContentService.GetDTOByNavId(noticeNavId, 2);
            model.NewsNav = newsNav;
            model.News = siteContentService.GetDTOByNavId(newsNavId, 2);
            model.About = siteContentService.GetInfoDTOByNavId(aboutNavId);
            model.StudyNav = studyNav;
            model.Study = siteContentService.GetDTOByNavId(studyNavId, 4);

            string html = MVCHelper.RenderViewToString(context, template, model);
            File.WriteAllText(context.HttpContext.Server.MapPath("~/Default.html"), html);
            //context.HttpContext.Response.Write("<p>首页 /Default.html</p>");
            //context.HttpContext.Response.Flush();
            return true;
        }

        #region 生成介绍页静态页
        /// <summary>
        /// 生成介绍页
        /// </summary>
        /// <param name="context"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static bool Info(ControllerContext context, long id)
        {
            SiteContentDTO info = siteContentService.GetDTOById(id);
            if (info == null)
            {
                throw new Exception("获取不到介绍页(Id:" + id + ")");
            }

            return Info(context, info);
        }

        /// <summary>
        /// 生成介绍页
        /// </summary>
        /// <param name="context"></param>
        /// <param name="info"></param>
        /// <returns></returns>
        private static bool Info(ControllerContext context, SiteContentDTO info)
        {
            string templateUrl = context.HttpContext.Server.MapPath(info.ViewHtmlTemplate);
            if (string.IsNullOrEmpty(info.ViewHtmlTemplate) || !File.Exists(templateUrl))
            {
                throw new Exception("获取不到介绍页(Id:" + info.Id + ")生成静态页模板");
            }

            PageViewModel model = new PageViewModel();
            #region 公共数据
            model.HeaderViewModel = GetHeaderViewModel(context);
            model.FooterViewModel = GetFooterViewModel(context);
            model.SiteConfig = AdminHelper.GetSiteConfig(context);
            #endregion
            model.Info = info;

            string html = MVCHelper.RenderViewToString(context, info.ViewHtmlTemplate, model);
            string fileDir = context.HttpContext.Server.MapPath("~/Info/");
            if (!Directory.Exists(fileDir))
            {
                Directory.CreateDirectory(fileDir);
            }
            File.WriteAllText(fileDir + info.Id + ".html", html);

            //context.HttpContext.Response.Write("<p>"+ info.Title + " /Info/"+ info.Id + ".html</p>");
            //context.HttpContext.Response.Flush();
            return true;
        }

        /// <summary>
        /// 批量生成介绍页
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static bool RebuildInfo(ControllerContext context)
        {
            SiteContentDTO[] infos = siteContentService.GetDTOByFunCode("info");
            foreach (SiteContentDTO info in infos)
            {
                Info(context, info);
            }

            return true;
        }
        #endregion

        #region 生成新闻资讯
        /// <summary>
        /// 生成新闻资讯详细页
        /// </summary>
        /// <param name="context"></param>
        /// <param name="news"></param>
        /// <returns></returns>
        public static bool News(ControllerContext context, long id)
        {
            SiteContentDTO news = siteContentService.GetDTOById(id);
            if (news == null)
            {
                throw new Exception("获取不到新闻资讯(Id:" + id + ")");
            }
            return News(context, news);
        }

        /// <summary>
        /// 生成新闻资讯详细页
        /// </summary>
        /// <param name="context"></param>
        /// <param name="news"></param>
        /// <returns></returns>
        public static bool News(ControllerContext context, SiteContentDTO news)
        {
            string templateUrl = context.HttpContext.Server.MapPath(news.ViewHtmlTemplate);
            if (string.IsNullOrEmpty(news.ViewHtmlTemplate) || !File.Exists(templateUrl))
            {
                throw new Exception("获取不到" + news.NavName + "(Id:" + news.Id + ")生成静态页模板");
            }

            PageViewModel model = new PageViewModel();

            #region 公共数据
            model.HeaderViewModel = GetHeaderViewModel(context);
            model.FooterViewModel = GetFooterViewModel(context);
            model.SiteConfig = AdminHelper.GetSiteConfig(context);
            #endregion
            model.Info = news;

            string html = MVCHelper.RenderViewToString(context, news.ViewHtmlTemplate, model);
            string fileDir = context.HttpContext.Server.MapPath("~/News/" + news.SiteNavId + "/");
            if (!Directory.Exists(fileDir))
            {
                Directory.CreateDirectory(fileDir);
            }
            File.WriteAllText(fileDir + news.Id + ".html", html);

            //context.HttpContext.Response.Write("<p>" + news.Title + " /News/" + news.SiteNavId + "/" + news.Id + ".html</p>");
            //context.HttpContext.Response.Flush();
            return true;
        }

        /// <summary>
        /// 生成新闻资讯列表
        /// </summary>
        /// <param name="context"></param>
        /// <param name="navId"></param>
        /// <returns></returns>
        public static bool NewsList(ControllerContext context, long navId)
        {
            SiteNavDTO nav = siteNavService.GetDTOById(navId);

            string templateUrl = context.HttpContext.Server.MapPath(nav.ListHtmlTemplate);
            if (string.IsNullOrEmpty(nav.ListHtmlTemplate) || !File.Exists(templateUrl))
            {
                throw new Exception("获取不到" + nav.NavName + "(NavId:" + nav.Id + ")生成静态页模板");
            }

            //总记录数
            int totalSize = siteContentService.GetDTOByNavId(navId).Count();
            //每页显示记录数
            int pageSize = 10;//每页10条
            //总页数
            int pageCount = (int)Math.Ceiling((totalSize * 1.0f) / (pageSize * 1.0f));

            //没有数据
            if (totalSize <= 0)
            {
                ListViewModel model = new ListViewModel();

                #region 公共数据
                model.HeaderViewModel = GetHeaderViewModel(context);
                model.FooterViewModel = GetFooterViewModel(context);
                model.SiteConfig = AdminHelper.GetSiteConfig(context);
                #endregion

                model.TotalCount = totalSize;
                model.PageIndex = 1;
                model.PageSize = pageSize;
                model.MaxPagerCount = pageCount;
                model.Nav = nav;
                model.ListInfo = null;

                string html = MVCHelper.RenderViewToString(context, nav.ListHtmlTemplate, model);
                string fileDir = context.HttpContext.Server.MapPath("~/News/" + navId + "/");
                if (!Directory.Exists(fileDir))
                {
                    Directory.CreateDirectory(fileDir);
                }
                File.WriteAllText(fileDir + "list-1.html", html);

                //context.HttpContext.Response.Write("<p>" + nav.NavName + " /News/" + navId + "/list-1.html</p>");
                //context.HttpContext.Response.Flush();
                return true;
            }

            for (int pageIndex = 1; pageIndex <= pageCount; pageIndex++)
            {
                ListViewModel model = new ListViewModel();
                #region 公共数据
                model.HeaderViewModel = GetHeaderViewModel(context);
                model.FooterViewModel = GetFooterViewModel(context);
                model.SiteConfig = AdminHelper.GetSiteConfig(context);
                #endregion

                model.TotalCount = totalSize;
                model.PageIndex = pageIndex;
                model.PageSize = pageSize;
                model.MaxPagerCount = pageCount;
                model.Nav = nav;
                long total;
                model.ListInfo = siteContentService.GetDTOPagedData(navId, out total, pageIndex, pageSize);

                string html = MVCHelper.RenderViewToString(context, nav.ListHtmlTemplate, model);
                string fileDir = context.HttpContext.Server.MapPath("~/News/" + navId + "/");
                if (!Directory.Exists(fileDir))
                {
                    Directory.CreateDirectory(fileDir);
                }
                File.WriteAllText(fileDir + "list-" + pageIndex + ".html", html);

                //context.HttpContext.Response.Write("<p>" + nav.NavName + " /News/" + navId + "/list-" + pageIndex + ".html</p>");
                //context.HttpContext.Response.Flush();

            }
            return true;
        }
        /// <summary>
        /// 根据菜单Id生成静态页
        /// </summary>
        /// <param name="context"></param>
        /// <param name="navId"></param>
        /// <returns></returns>
        public static bool RebuildNews(ControllerContext context, long navId)
        {
            //生成新闻资讯详细页
            SiteContentDTO[] listNews = siteContentService.GetDTOByNavId(navId);
            foreach (SiteContentDTO news in listNews)
            {
                News(context, news);
            }

            //生成新闻资讯列表
            NewsList(context, navId);
            return true;
        }

        /// <summary>
        /// 批量生成新闻资讯静态页
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static bool RebuildNews(ControllerContext context)
        {
            SiteNavDTO[] navs = siteNavService.GetSiteNavsByFunCode("News");
            foreach (SiteNavDTO nav in navs)
            {
                RebuildNews(context, nav.Id);
            }
            return true;
        }
        #endregion

        #region 生成资料下载
        /// <summary>
        /// 生成资料下载列表
        /// </summary>
        /// <param name="context"></param>
        /// <param name="navId"></param>
        /// <returns></returns>
        public static bool DownloadList(ControllerContext context, long navId)
        {
            SiteNavDTO nav = siteNavService.GetDTOById(navId);
            string templateUrl = context.HttpContext.Server.MapPath(nav.ListHtmlTemplate);
            if (string.IsNullOrEmpty(nav.ListHtmlTemplate) || !File.Exists(templateUrl))
            {
                throw new Exception("获取不到" + nav.NavName + "(NavId:" + nav.Id + ")生成静态页模板");
            }
            //总记录数
            int totalSize = siteContentService.GetDTOByNavId(navId).Count();
            //每页显示记录数
            int pageSize = 10;//每页10条
            //总页数
            int pageCount = (int)Math.Ceiling((totalSize * 1.0f) / (pageSize * 1.0f));

            //没有数据
            if (totalSize <= 0)
            {
                ListViewModel model = new ListViewModel();
                #region 公共数据
                model.HeaderViewModel = GetHeaderViewModel(context);
                model.FooterViewModel = GetFooterViewModel(context);
                model.SiteConfig = AdminHelper.GetSiteConfig(context);
                #endregion

                model.TotalCount = totalSize;
                model.PageIndex = 1;
                model.PageSize = pageSize;
                model.MaxPagerCount = pageCount;
                model.Nav = nav;
                model.ListInfo = null;

                string html = MVCHelper.RenderViewToString(context, nav.ListHtmlTemplate, model);
                string fileDir = context.HttpContext.Server.MapPath("~/Download/" + navId + "/");
                if (!Directory.Exists(fileDir))
                {
                    Directory.CreateDirectory(fileDir);
                }
                File.WriteAllText(fileDir + "list-1.html", html);

                //context.HttpContext.Response.Write("<p>" + nav.NavName + " /Download/" + navId + "/list-1.html</p>");
                //context.HttpContext.Response.Flush();

                return true;
            }

            for (int pageIndex = 1; pageIndex <= pageCount; pageIndex++)
            {
                ListViewModel model = new ListViewModel();
                #region 公共数据
                model.HeaderViewModel = GetHeaderViewModel(context);
                model.FooterViewModel = GetFooterViewModel(context);
                model.SiteConfig = AdminHelper.GetSiteConfig(context);
                #endregion

                model.TotalCount = totalSize;
                model.PageIndex = pageIndex;
                model.PageSize = pageSize;
                model.MaxPagerCount = pageCount;
                model.Nav = nav;
                long total;
                model.ListInfo = siteContentService.GetDTOPagedData(navId, out total, pageIndex, pageSize);

                string html = MVCHelper.RenderViewToString(context, nav.ListHtmlTemplate, model);
                string fileDir = context.HttpContext.Server.MapPath("~/Download/" + navId + "/");
                if (!Directory.Exists(fileDir))
                {
                    Directory.CreateDirectory(fileDir);
                }
                File.WriteAllText(fileDir + "list-" + pageIndex + ".html", html);

                //context.HttpContext.Response.Write("<p>" + nav.NavName + " /Download/" + navId + "/list-" + pageIndex + ".html</p>");
                //context.HttpContext.Response.Flush();
            }
            return true;
        }
        /// <summary>
        /// 根据菜单Id生成静态页
        /// </summary>
        /// <param name="context"></param>
        /// <param name="navId"></param>
        /// <returns></returns>
        public static bool RebuildDownload(ControllerContext context, long navId)
        {
            //生成资料下载列表
            DownloadList(context, navId);
            return true;
        }

        /// <summary>
        /// 批量生成资料下载静态页
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static bool RebuildDownload(ControllerContext context)
        {
            SiteNavDTO[] navs = siteNavService.GetSiteNavsByFunCode("Download");
            foreach (SiteNavDTO nav in navs)
            {
                RebuildDownload(context, nav.Id);
            }
            return true;
        }
        #endregion

        #region 生成友情链接
        /// <summary>
        /// 生成友情链接列表
        /// </summary>
        /// <param name="context"></param>
        /// <param name="navId"></param>
        /// <returns></returns>
        public static bool LinkList(ControllerContext context, long navId)
        {
            SiteNavDTO nav = siteNavService.GetDTOById(navId);
            string templateUrl = context.HttpContext.Server.MapPath(nav.ListHtmlTemplate);
            if (string.IsNullOrEmpty(nav.ListHtmlTemplate) || !File.Exists(templateUrl))
            {
                throw new Exception("获取不到" + nav.NavName + "(NavId:" + nav.Id + ")生成静态页模板");
            }
            //总记录数
            int totalSize = siteContentService.GetDTOByNavId(navId).Count();
            //每页显示记录数
            int pageSize = 10;//每页10条
            //总页数
            int pageCount = (int)Math.Ceiling((totalSize * 1.0f) / (pageSize * 1.0f));

            //没有数据
            if (totalSize <= 0)
            {
                ListViewModel model = new ListViewModel();
                #region 公共数据
                model.HeaderViewModel = GetHeaderViewModel(context);
                model.FooterViewModel = GetFooterViewModel(context);
                model.SiteConfig = AdminHelper.GetSiteConfig(context);
                #endregion

                model.TotalCount = totalSize;
                model.PageIndex = 1;
                model.PageSize = pageSize;
                model.MaxPagerCount = pageCount;
                model.Nav = nav;
                model.ListInfo = null;

                string html = MVCHelper.RenderViewToString(context, nav.ListHtmlTemplate, model);
                string fileDir = context.HttpContext.Server.MapPath("~/Link/" + navId + "/");
                if (!Directory.Exists(fileDir))
                {
                    Directory.CreateDirectory(fileDir);
                }
                File.WriteAllText(fileDir + "list-1.html", html);

                //context.HttpContext.Response.Write("<p>" + nav.NavName + " /Link/" + navId + "/list-1.html</p>");
                //context.HttpContext.Response.Flush();

                return true;
            }

            for (int pageIndex = 1; pageIndex <= pageCount; pageIndex++)
            {
                ListViewModel model = new ListViewModel();
                #region 公共数据
                model.HeaderViewModel = GetHeaderViewModel(context);
                model.FooterViewModel = GetFooterViewModel(context);
                model.SiteConfig = AdminHelper.GetSiteConfig(context);
                #endregion

                model.TotalCount = totalSize;
                model.PageIndex = pageIndex;
                model.PageSize = pageSize;
                model.MaxPagerCount = pageCount;
                model.Nav = nav;
                long total;
                model.ListInfo = siteContentService.GetDTOPagedData(navId, out total, pageIndex, pageSize);

                string html = MVCHelper.RenderViewToString(context, nav.ListHtmlTemplate, model);
                string fileDir = context.HttpContext.Server.MapPath("~/Link/" + navId + "/");
                if (!Directory.Exists(fileDir))
                {
                    Directory.CreateDirectory(fileDir);
                }
                File.WriteAllText(fileDir + "list-" + pageIndex + ".html", html);

                //context.HttpContext.Response.Write("<p>" + nav.NavName + " /Link/" + navId + "/list-" + pageIndex + ".html</p>");
                //context.HttpContext.Response.Flush();
            }
            return true;
        }

        /// <summary>
        /// 根据菜单Id生成静态页
        /// </summary>
        /// <param name="context"></param>
        /// <param name="navId"></param>
        /// <returns></returns>
        public static bool RebuildLink(ControllerContext context, long navId)
        {
            //生成友情链接列表
            LinkList(context, navId);
            return true;
        }

        /// <summary>
        /// 批量生成友情链接静态页
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static bool RebuildLink(ControllerContext context)
        {
            SiteNavDTO[] navs = siteNavService.GetSiteNavsByFunCode("Link");
            foreach (SiteNavDTO nav in navs)
            {
                RebuildLink(context, nav.Id);
            }
            return true;
        }
        #endregion

        /// <summary>
        /// 生成整站静态页
        /// </summary>
        /// <param name="context"></param>
        /// <param name="key"></param>
        public static void RebuildAll(ControllerContext context, string key)
        {
            context.HttpContext.Response.Write("<p>***************** 生成整站静态页 begin *******************</p>");
            context.HttpContext.Response.Flush();
            //生成首页静态页
            Home(context);
            context.HttpContext.Response.Write("<p>***************** 首页静态页生成成功 *******************</p>");
            context.HttpContext.Response.Flush();
            //生成介绍页静态页
            RebuildInfo(context);
            context.HttpContext.Response.Write("<p>***************** 介绍页静态页生成成功 *******************</p>");
            context.HttpContext.Response.Flush();
            //生成新闻资讯
            RebuildNews(context);
            context.HttpContext.Response.Write("<p>***************** 新闻资讯静态页生成成功 *******************</p>");
            context.HttpContext.Response.Flush();
            //生成资料下载
            RebuildDownload(context);
            context.HttpContext.Response.Write("<p>***************** 资料下载静态页生成成功 *******************</p>");
            context.HttpContext.Response.Flush();
            //生成友情链接
            RebuildLink(context);
            context.HttpContext.Response.Write("<p>***************** 友情链接静态页生成成功 *******************</p>");
            context.HttpContext.Response.Flush();
            context.HttpContext.Response.Write("<p>***************** 生成整站静态页 end *******************</p>");
            context.HttpContext.Response.Flush();
        }
    }
}